# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=yelp-tools
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=3.32.2
pkgrel=1
pkgdesc="Tools for creating Yelp documentation (mingw-w64)"
arch=('any')
license=('GPL')
url="https://www.gnome.org"
depends=("intltool"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-libxslt" 
         "${MINGW_PACKAGE_PREFIX}-itstool"
         "${MINGW_PACKAGE_PREFIX}-python3-mallard-ducktype"
         "${MINGW_PACKAGE_PREFIX}-yelp-xsl")
options=('strip' '!libtool' 'staticlibs')
source=(https://download.gnome.org/sources/${_realname}/${pkgver:0:4}/${_realname}-$pkgver.tar.xz
        yelp-no-symlinks.patch)
sha256sums=('183856b5ed0b0bb2c05dd1204af023946ed436943e35e789afb0295e5e71e8f9'
            '276286ade313f9c31a990e77742b20a34c59d50f84a21e5d05c38e5a8ee654be')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/yelp-no-symlinks.patch
  autoreconf -ivf
}

build() {
  export PYTHON=${MINGW_PREFIX}/bin/python3
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}
  ${srcdir}/${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${CHOST} \
    --host=${CHOST} \
    --sysconfdir=${MINGW_PREFIX}/etc \
    --localstatedir=${MINGW_PREFIX}/var

  make
}

package() {
  cd ${srcdir}/build-${CARCH}
  make DESTDIR="${pkgdir}" install
  local WIN_PREFIX="$(cygpath -m ${MINGW_PREFIX})"
  for ff in yelp-build yelp-check yelp-new; do
    sed -e "s| xsltproc| ${MINGW_PREFIX}/bin/xsltproc|g" \
     -e "s|${WIN_PREFIX}|${MINGW_PREFIX}|g" \
     -i ${pkgdir}/${MINGW_PREFIX}/bin/$ff
  done
  for ff in mal-ncx mal-opf; do
    sed -e "s|${WIN_PREFIX}|${MINGW_PREFIX}|g" \
     -i ${pkgdir}${MINGW_PREFIX}/share/yelp-tools/xslt/$ff.xsl
  done
}
